<template>
  <view class="container">
    <view class="form">
      <text class="title">注册</text>
      <input class="input" placeholder="请输入用户名" v-model="username"/>
      <input class="input" placeholder="请输入密码" password v-model="password"/>
      <input class="input" placeholder="请确认密码" password v-model="confirmPassword"/>
      <button class="btn" type="primary" @click="handleRegister">注册</button>
      <view class="link">
        <text>已有账号？</text>
        <navigator url="/pages/demos/login/login" open-type="navigateBack">去登录</navigator>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      confirmPassword: '',
    }
  },
  methods: {
    handleRegister() {
      if (!this.username || !this.password || !this.confirmPassword) {
        uni.showToast({
          title: '请输入完整信息',
          icon: 'none'
        })
        return
      }
      
      if (this.password !== this.confirmPassword) {
        uni.showToast({
          title: '两次密码输入不一致',
          icon: 'none'
        })
        return
      }
      
      // 这里可以添加实际的注册逻辑
      uni.showToast({
        title: '注册成功',
        icon: 'success'
      })
      
      // 注册成功后跳转到登录页
      setTimeout(() => {
        uni.navigateBack()
      }, 1500)
    }
  }
}
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f5f5;
}

.form {
  display: flex;
  flex-direction: column;
  width: 80%;
  padding: 40rpx;
  background-color: white;
  border-radius: 20rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}

.title {
  font-size: 48rpx;
  font-weight: bold;
  text-align: center;
  margin-bottom: 60rpx;
  color: #333;
}

.input {
  height: 80rpx;
  border: 2rpx solid #e0e0e0;
  border-radius: 10rpx;
  padding: 0 20rpx;
  margin-bottom: 30rpx;
  font-size: 28rpx;
}

.input:focus {
  border-color: #007AFF;
}

.btn {
  height: 80rpx;
  border-radius: 10rpx;
  margin-top: 20rpx;
  font-size: 32rpx;
  background-color: #007AFF;
}

.link {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 40rpx;
  font-size: 28rpx;
}

.link text {
  color: #666;
}

.link navigator {
  color: #007AFF;
  margin-left: 10rpx;
}
</style>